﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.ServiceLocation;

namespace MoqContrib.AutoMock.CommonServiceLocator
{
    /// <summary>
    /// 
    /// </summary>
    public class AutoMockContainer : ServiceLocatorImplBase, 
        MoqContrib.AutoMock.CommonServiceLocator.IAutoMockContainer
    {

        /// <summary>
        /// 
        /// </summary>
        protected internal IAutoMocker _helper;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="helper"></param>
        public AutoMockContainer(IAutoMocker helper)
        {
            _helper = helper;
        }

        /// <summary>
        /// 
        /// </summary>
        public AutoMockContainer() {}

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceType"></param>
        /// <returns></returns>
        protected override IEnumerable<object> DoGetAllInstances(Type serviceType)
        {
            return new[] { DoGetInstance(serviceType, null) };
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceType"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        protected override object DoGetInstance(Type serviceType, string key)
        {
            return Mock.Get(serviceType).Object;
        }

        #region IAutoMockContainer Members

        /// <summary>
        /// 
        /// </summary>
        public virtual IAutoMocker Mock
        {
            get { return _helper; }
        }

        #endregion
    }
}
